package com.gdth.bank.activity;

import java.io.File;
import java.io.IOException;
import java.io.Serializable;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.support.v4.content.FileProvider;
import android.text.Editable;
import android.text.InputType;
import android.text.TextWatcher;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewGroup.MarginLayoutParams;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

import com.gdth.bank.BankApplication;
import com.gdth.bank.R;
import com.gdth.bank.adapter.GmJjDjJjRrAdapter;
import com.gdth.bank.adapter.GmJjDjJjRrAdapter.OnJtcyXxDetailClickListener;
import com.gdth.bank.adapter.GmJjDjListViewAdapter;
import com.gdth.bank.adapter.GmJjDjListViewAdapter.OnDeleteListener;
import com.gdth.bank.bean.DbjjItem;
import com.gdth.bank.bean.TAppGmjjdjJc;
import com.gdth.bank.bean.TAppGmjjdjLc;
import com.gdth.bank.bean.TAppGmjjdjNy;
import com.gdth.bank.model.DjjjdjItem;
import com.gdth.bank.presenter.SynchronizePresenter;
import com.gdth.bank.utils.AppUtil;
import com.gdth.bank.view.GmJjDjView;
import com.gdth.bank.widget.BankDrawDownListTextView;
import com.gdth.bank.widget.BankEditText;
import com.gdth.bank.widget.image.Bimp;
import com.gdth.core.annotation.view.ViewInject;
import com.gdth.core.widget.BaseActivity;
import com.gdth.database.bean.TAppFjxxb;
import com.gdth.database.bean.TAppYh;
import com.gdth.model.Item;
import com.gdth.utils.DateTimePickDialogUtil;
import com.gdth.utils.GsonUtil;
import com.gdth.utils.ToolUtil;
import com.gdth.utils.UUIDUtil;
import com.gdth.widget.dialog.BaseToast;
import com.gdth.widget.dialog.DialogConfig;
import com.gdth.widget.dwonloadlist.BaseDownListTextView.OnSelectListener;

public class GmJjDjActivity extends BaseActivity implements GmJjDjView{
	@ViewInject(id=R.id.header_label_title) TextView txt_header_title;
	@ViewInject(id=R.id.header_btn_left, click="finishClick") TextView txt_header_left;
	@ViewInject(id=R.id.header_btn_right, click="saveClick") TextView photo_bt_del;
	@ViewInject(id=R.id.gmjjdj_gw)  BankDrawDownListTextView drawDownList_gmjjdj_gw;
	@ViewInject(id=R.id.gmjjdj_jsr) BankDrawDownListTextView drawDownList_gmjjdj_jsr;
	@ViewInject(id=R.id.gmjjdj_jjr) BankDrawDownListTextView drawDownList_gmjjdj_jjr;
	@ViewInject(id=R.id.gmjjdj_jcr) BankEditText txt_jcr;
	@ViewInject(id=R.id.gmjjdj_fjmc) BankEditText txt_gmjjdj_fjmc;
	@ViewInject(id=R.id.gmjjdj_gmjjdj_zl) BankDrawDownListTextView drawDownList_gmjjdj_zl;
	@ViewInject(id=R.id.gmjjdj_fj, click="selectImage") ImageView img_tp;
	@ViewInject(id=R.id.gmjjdj_list, itemClick="onItemClick") ListView gmjjdj_list;
	@ViewInject(id=R.id.gmjjdj_fj_gridview, itemClick="onItemClick") ListView gmjjdj_fj_gridview;
	ImageView dataImageView;
	TextView dataTextView,gmjjdj_yjhsfxgmm,gmjjdj_sws_label,gmjjdj_ce_label;
	EditText dataEditText,gmjjdj_yjyzEditText,gmjjdj_ysEditText,gmjjdj_qtyjsxEditText,gmjjdj_gmjjdj_bz,gmjjdj_gmjjdj_zms,gmjjdj_gmjjdj_sws_txt,gmjjdj_gmjjdj_ce_txt;
	Button gmjjdj_tjjjnrButton,gmjjdj_tj_fjButton,gmjjdj_tj_button,gmjjdj_tjjjnr_bc,gmjjdj_bty_button;
	RadioGroup gmjjdj_zzxjsbmmsfyjRadioGroup,gmjjdj_zzxjsbmmsfyj_yjRadioGroup;  
    RadioButton radioButton_shiRadioButton,radioButton_fouRadioButton,radioButton_weiRadioButton,radioButton_shiRadioButton2,radioButton_fouRadioButton2,radioButton_weiRadioButton2;  
    List<Item> gwjson = new ArrayList<Item>();
    List<Item> json = new ArrayList<Item>();
    List<Item> bmjson = new ArrayList<Item>();
    GmJjDjJjRrAdapter adapter;
    List<DjjjdjItem> items;
    String  savePath,uuid,wjlx = "jpg";
	String savePath1, uuid1,jjnrId="";
	GmJjDjListViewAdapter fjadapter;
	List<TAppFjxxb> fjxxList,fjgxList,scfjList;
	int scposition,radioGroupId=0,radioGroupId2=0,jjnrid;
	DialogConfig config;
	ProgressDialog mProgressDialog;
	TAppGmjjdjJc mTAppGmjjDjJc;
	SynchronizePresenter presenter;
	TAppFjxxb tAppFjxxb;
	List<TAppGmjjdjNy>  mTAppGmjjDjNyBeanList,scmTAppGmjjDjNyList;
	String id,yjtxt,zhblr,spzt,lczt,djId,wybs,xlbs;
	LinearLayout gmjjdj_yjhsfxgmm_layout,gmjjdj_ce_layout,gmjjdj_bty_layout;
	private static final int ACCURACYNUM = 2;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_gmjjdj);
		initPresent();
		initView();
		init();
		
		
		
	}
	private void initPresent() {
		mProgressDialog = new ProgressDialog(this);
		mProgressDialog.setCancelable(false);
		String json = BankApplication.mInstance.getCurrentUserForJson();
		TAppYh user = GsonUtil.getGson().fromJson(json, TAppYh.class);
		presenter = new SynchronizePresenter(this);
		 mTAppGmjjDjNyBeanList= new ArrayList<TAppGmjjdjNy>();
		 scmTAppGmjjDjNyList = new ArrayList<TAppGmjjdjNy>();
		Intent intent= getIntent();
		id = intent.getStringExtra("id");
		zhblr=intent.getStringExtra("zhblr");
		spzt = intent.getStringExtra("spzt");
		lczt =intent.getStringExtra("lczt");
		String bmid = user.getBmid();
		if(id!=null){
			if(lczt.equals("1") || lczt.equals("2")){
				wybs="{\"sfz\":\""+user.getSfz()+"\",\"bs\":\"3\"}";
				presenter.getGwList(wybs.toString());
			}else{
			wybs="{\"sfz\":\""+user.getSfz()+"\",\"bs\":\"1\"}";
			presenter.getGwList(wybs.toString());}
		}else{
			wybs="{\"sfz\":\""+user.getSfz()+"\",\"bs\":\"0\"}";
			presenter.getGwList(wybs.toString());
		}
		
		presenter.getBmList(bmid);
//		if(id!=null){
//			presenter.getDbjjdjJson(id);;
//		}else{
//			presenter.getdjJson(user.getSfz());
//		}
		
		
	}
	
	private void initView() {
		// TODO Auto-generated method stub
		txt_header_title.setText(getResources().getString(R.string.param203));
		photo_bt_del.setVisibility(View.INVISIBLE);
		dataImageView=(ImageView) findViewById(R.id.gmjjdj_jjsj_image);
		dataImageView.setClickable(false);
		dataTextView=(TextView) findViewById(R.id.gmjjdj_jjsj_label);
		dataTextView.setText(getResources().getString(R.string.param204));
		dataEditText=(EditText) findViewById(R.id.gmjjdj_jjsj_edit);
		dataEditText.setEnabled(false);
		txt_jcr.setLabel(R.string.gmjjdj_jcr_tx);
		txt_jcr.setHint(R.string.gmjjdj_jcr_tx_hint);
		txt_jcr.setImage(null);
		TAppYh user = BankApplication.mInstance.getCurrentUser();
		if(id==null){
		txt_jcr.setValue(user.getXm());
		txt_jcr.mEditText.setEnabled(false);
		}
		txt_gmjjdj_fjmc.setLabel(getResources().getString(R.string.param205));
		txt_gmjjdj_fjmc.setHint(R.string.gmjjdj_jjr_fjmc_hint);
		txt_gmjjdj_fjmc.setImage(null);
		drawDownList_gmjjdj_jsr.setLabel(R.string.gmjjdj_jsr_tx);
		drawDownList_gmjjdj_jsr.mEditText.setHint(R.string.gmjjdj_jsr_tx_hint);
//		gwjson=AppUtil.getCanshuByType(this, AppUtil.SHARE_DATA_GW);
		drawDownList_gmjjdj_jjr.setLabel(R.string.gmjjdj_jjr_tx);
		drawDownList_gmjjdj_jjr.mEditText.setHint(R.string.gmjjdj_jjr_tx_hint);
//		drawDownList_gmjjdj_jjr.setItem(json);
		drawDownList_gmjjdj_gw.setLabel(R.string.gmjjdj_gw_tx);
		drawDownList_gmjjdj_gw.mEditText.setHint(R.string.gmjjdj_gw_tx_hint);
		gmjjdj_yjyzEditText= (EditText) findViewById(R.id.gmjjdj_yjyz);
		gmjjdj_ysEditText= (EditText) findViewById(R.id.gmjjdj_ys);
		gmjjdj_gmjjdj_zms=(EditText) findViewById(R.id.gmjjdj_gmjjdj_zms);
		gmjjdj_qtyjsxEditText=(EditText) findViewById(R.id.gmjjdj_qtyjsx);
		gmjjdj_gmjjdj_bz = (EditText) findViewById(R.id.gmjjdj_gmjjdj_bz);
		gmjjdj_tjjjnrButton=(Button) findViewById(R.id.gmjjdj_tjjjnr);
		gmjjdj_tj_fjButton=(Button) findViewById(R.id.gmjjdj_tj_fj);
		gmjjdj_tj_button=(Button) findViewById(R.id.gmjjdj_tj_button);
		gmjjdj_tjjjnr_bc= (Button) findViewById(R.id.gmjjdj_tjjjnr_bc);
		gmjjdj_tjjjnr_bc.setVisibility(View.GONE);
		gmjjdj_bty_button=(Button) findViewById(R.id.gmjjdj_bty_button);
		gmjjdj_zzxjsbmmsfyjRadioGroup=(RadioGroup) findViewById(R.id.gmjjdj_zzxjsbmmsfyj);
		gmjjdj_zzxjsbmmsfyj_yjRadioGroup=(RadioGroup) findViewById(R.id.gmjjdj_zzxjsbmmsfyj_yj);
		radioButton_shiRadioButton=(RadioButton) findViewById(R.id.radioButton_shi);
		radioButton_fouRadioButton=(RadioButton) findViewById(R.id.radioButton_fou);
		radioButton_weiRadioButton=(RadioButton) findViewById(R.id.radioButton_wei);
		radioButton_shiRadioButton2=(RadioButton) findViewById(R.id.radioButton_shi_yj);
		radioButton_fouRadioButton2=(RadioButton) findViewById(R.id.radioButton_fou_yj);
		radioButton_weiRadioButton2=(RadioButton) findViewById(R.id.radioButton_wei_yj);
		gmjjdj_yjhsfxgmm_layout = (LinearLayout) findViewById(R.id.gmjjdj_yjhsfxgmm_layout);
		gmjjdj_yjhsfxgmm_layout.setVisibility(View.GONE);
		gmjjdj_bty_layout=(LinearLayout) findViewById(R.id.gmjjdj_bty_layout);
		drawDownList_gmjjdj_zl.setLabel(getResources().getString(R.string.param206));
		gmjjdj_yjhsfxgmm= (TextView) findViewById(R.id.gmjjdj_yjhsfxgmm_label);
		gmjjdj_yjhsfxgmm.setVisibility(View.GONE);
		json=AppUtil.getCanshuByType(this, AppUtil.SHARE_DATA_JJZL);
		drawDownList_gmjjdj_zl.setItem(json);
		gmjjdj_sws_label = (TextView) findViewById(R.id.gmjjdj_sws_label);
		gmjjdj_gmjjdj_sws_txt = (EditText) findViewById(R.id.gmjjdj_gmjjdj_sws_txt);
		gmjjdj_sws_label.setVisibility(View.GONE);
		gmjjdj_gmjjdj_sws_txt.setVisibility(View.GONE);
		gmjjdj_zzxjsbmmsfyjRadioGroup.setOnCheckedChangeListener(new RadioGroupListener());  
		gmjjdj_zzxjsbmmsfyj_yjRadioGroup.setOnCheckedChangeListener(new RadioGroupListener());
		gmjjdj_tjjjnrButton.setOnClickListener(new AddMyClick());
		gmjjdj_tj_fjButton.setOnClickListener(new AddMyClick());
		gmjjdj_tj_button.setOnClickListener(new AddMyClick());
		gmjjdj_tjjjnr_bc.setOnClickListener(new AddMyClick());
//		dataImageView.setOnClickListener(new AddMyClick());
		gmjjdj_bty_button.setOnClickListener(new AddMyClick());
		gmjjdj_gmjjdj_zms.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL); 
		gmjjdj_gmjjdj_zms.addTextChangedListener(watcher);
		//实物数实时获取
		gmjjdj_gmjjdj_zms.setOnKeyListener(new View.OnKeyListener() {
			
			@Override
			public boolean onKey(View v, int keyCode, KeyEvent event) {
				// TODO Auto-generated method stub
				gmjjdj_gmjjdj_sws_txt.setText(gmjjdj_gmjjdj_zms.getText().toString());
				return false;
			}
		});
		gmjjdj_gmjjdj_zms.addTextChangedListener(new TextWatcher() {
			
			@Override
			public void onTextChanged(CharSequence s, int start, int before, int count) {
				// TODO Auto-generated method stub
				gmjjdj_gmjjdj_sws_txt.setText(gmjjdj_gmjjdj_zms.getText().toString());
			}
			
			@Override
			public void beforeTextChanged(CharSequence s, int start, int count,
					int after) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void afterTextChanged(Editable s) {
				// TODO Auto-generated method stub
				
			}
		});
		
	}
	private void init() {
		mTAppGmjjDjJc = new TAppGmjjdjJc();
		items = new ArrayList<DjjjdjItem>();
		adapter = new GmJjDjJjRrAdapter(this, items);
		gmjjdj_list.setAdapter(adapter);
		gmjjdj_list.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				// TODO Auto-generated method stub
				jjnrId=position+"";
				DjjjdjItem mImageItem= items.get(position);
				drawDownList_gmjjdj_zl.setValue(mImageItem.getKey().toString());
				gmjjdj_gmjjdj_zms.setText(mImageItem.getValue());
				gmjjdj_gmjjdj_sws_txt.setText(mImageItem.getSws().toString());
				gmjjdj_gmjjdj_bz.setText(mImageItem.getBz());
				
			}
		});
		fjxxList = new ArrayList<TAppFjxxb>();
		scfjList = new ArrayList<TAppFjxxb>();
		fjadapter = new GmJjDjListViewAdapter(this, fjxxList);
		gmjjdj_fj_gridview.setAdapter(fjadapter);
		adapter.setmOnJtcyXxDetailClickListener(new OnDetailClickListener());
		fjadapter.setmOnDeleteListener(new DeleteOnClickListener());
		gmjjdj_fj_gridview.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(GmJjDjActivity.this, GmjjPhotoActivity.class);
				intent.putExtra("fjxxList", (Serializable)fjxxList);
				intent.putExtra("ID", position);
				startActivity(intent);
			}
		});
	}
	class RadioGroupListener implements RadioGroup.OnCheckedChangeListener{  
        @Override  
        public void onCheckedChanged(RadioGroup group, int checkedId) {  
            if (checkedId==radioButton_shiRadioButton.getId()){  
            	radioGroupId=1;
            	radioGroupId2=1;
            }else if (checkedId==radioButton_fouRadioButton.getId()){  
            	radioGroupId=2;
            	radioGroupId2=2;
            }else if(checkedId==radioButton_weiRadioButton.getId()){
            	radioGroupId=3;
            	radioGroupId2=3;
            }else if(checkedId==radioButton_shiRadioButton2.getId()){
            	radioGroupId2=1;
            }else if(checkedId==radioButton_fouRadioButton2.getId()){
            	radioGroupId2=2;
            }else if(checkedId==radioButton_weiRadioButton2.getId()){
            	radioGroupId2=3;
            }
        }  
   }

	class AddMyClick implements OnClickListener{

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			switch (v.getId()) {
			case R.id.gmjjdj_tjjjnr:
				if(drawDownList_gmjjdj_zl.mEditText.getText().toString().equals("")){
					showMessage(getResources().getString(R.string.param207));
					return;
					}
				if(gmjjdj_gmjjdj_zms.getText().toString().equals("")){
					showMessage(getResources().getString(R.string.param208));
					return;
					}
				savejjnr();
				jjreset();
				break;
			case R.id.gmjjdj_jjsj_image:
				Date date= new Date();
				DateTimePickDialogUtil dateTimePicKDialog = new DateTimePickDialogUtil(  
						GmJjDjActivity.this); 
				 dateTimePicKDialog.dateTimePicKDialog(dataEditText); 
				break;
			case R.id.gmjjdj_tj_fj:
				savefj();
				break;
			case R.id.gmjjdj_tj_button:
//				saveqbList();
				ifSaveList();
				break;
			case R.id.gmjjdj_tjjjnr_bc:
				if(jjnrId.equals("")){
					showMessage(getResources().getString(R.string.param209));
					
				}else{
					savebc(jjnrId);
				}
				break;
			case R.id.gmjjdj_bty_button:
				btyDialog();
				break;
			default:
				break;
			}
			
		}

		private void savebc(String jjnrId) {
			// TODO Auto-generated method stub
			jjnrid =Integer.valueOf(jjnrId);
			DjjjdjItem mImageItem=items.get(jjnrid);
			items.remove(jjnrid);
//			DjjjdjItem mImageItem= new DjjjdjItem();
			mImageItem.setKey(drawDownList_gmjjdj_zl.getkey().toString());
			mImageItem.setImg(drawDownList_gmjjdj_zl.getValue());
			mImageItem.setZms(new BigDecimal(gmjjdj_gmjjdj_zms.getText().toString()));
			mImageItem.setValue(gmjjdj_gmjjdj_zms.getText().toString());
			mImageItem.setBz(gmjjdj_gmjjdj_bz.getText().toString());
			mImageItem.setSws(new BigDecimal(gmjjdj_gmjjdj_sws_txt.getText().toString()));
//			mImageItem.setCc(gmjjdj_gmjjdj_ce_txt.getText().toString());
			mImageItem.setGnlj("删除");
			items.add(mImageItem);
			showMessage("保存成功");
			adapter.notifyDataSetChanged();
			
		}

		private void savejjnr() {
			// TODO Auto-generated method stub
			DjjjdjItem  mImageItem=new DjjjdjItem();
			mImageItem.setKey(drawDownList_gmjjdj_zl.getkey().toString());
			mImageItem.setImg(drawDownList_gmjjdj_zl.getValue());
			mImageItem.setValue(gmjjdj_gmjjdj_zms.getText().toString());
			mImageItem.setBz(gmjjdj_gmjjdj_bz.getText().toString());
			mImageItem.setSws(new BigDecimal(gmjjdj_gmjjdj_sws_txt.getText().toString()));
			mImageItem.setZms(new BigDecimal(gmjjdj_gmjjdj_zms.getText().toString()));
			mImageItem.setGnlj("删除");
			items.add(mImageItem);
			adapter.notifyDataSetChanged();
			setListViewHeightBasedOnChildren(gmjjdj_list);
		}

		private void savefj() {
			// TODO Auto-generated method stub
			if (savePath == null || savePath.equals("")) {
				Toast.makeText(GmJjDjActivity.this, getResources().getString(R.string.param210), Toast.LENGTH_LONG).show();
				return;
			}
			if (txt_gmjjdj_fjmc.getValue().equals("")) {
				Toast.makeText(GmJjDjActivity.this, getResources().getString(R.string.param211), Toast.LENGTH_LONG).show();
				return;
			}
			TAppYh user = BankApplication.mInstance.getCurrentUser();
		
            	tAppFjxxb = new TAppFjxxb();
            	tAppFjxxb.setAppdz(savePath);
            	tAppFjxxb.setCjsj(new Date());
            	tAppFjxxb.setGnmk(4);
            	tAppFjxxb.setSczt(0);
            	tAppFjxxb.setSfz(user.getSfz());
            	tAppFjxxb.setUuid(uuid);
            	tAppFjxxb.setWjlx(wjlx);
            	tAppFjxxb.setWybs(uuid);
            	tAppFjxxb.setZdlx(1);
            	tAppFjxxb.setWjmc(txt_gmjjdj_fjmc.getValue().toString()+ "." + wjlx);
            	fjxxList.add(tAppFjxxb);
			updateGridView();
			setListViewHeightBasedOnChildren(gmjjdj_fj_gridview);
			reset();
		}
		
	}
	public void setListViewHeightBasedOnChildren(ListView listView) {  
		  
		  ListAdapter listAdapter = listView.getAdapter();  
		  
		  if (listAdapter == null) {  
		   return;  
		  }  
		  
		  int totalHeight = 0;  
		  
		  for (int i = 0; i < listAdapter.getCount(); i++) {  
		   View listItem = listAdapter.getView(i, null, listView);  
		   listItem.measure(0, 0);  
		   totalHeight += listItem.getMeasuredHeight();  
		  }  
		  
		  ViewGroup.LayoutParams params = listView.getLayoutParams();  
		  
		  params.height = totalHeight  
		    + (listView.getDividerHeight() * (listAdapter.getCount() - 1));  
		  
		  ((MarginLayoutParams) params).setMargins(10, 10, 10, 10); // 可删除  
		  
		  listView.setLayoutParams(params);  
		 }  
	/**
	 * 点击拍照
	 * @param arg0
	 */
	public void selectImage(View arg0) {
		String status=Environment.getExternalStorageState(); 
		if(status.equals(Environment.MEDIA_MOUNTED)) {
			Intent mIntent = new Intent();
			mIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); //添加这一句表示对目标应用临时授权该Uri所代表的文件
			mIntent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);//设置Action为拍照
			mIntent.putExtra(MediaStore.EXTRA_OUTPUT, getUri());//将拍取的照片保存到指定URI
			mIntent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 0);
			this.startActivityForResult(mIntent, AppUtil.activity_photo_requestcode);
		}  else { 
			BaseToast.getInstance().ShowSystemToast(GmJjDjActivity.this, getResources().getString(R.string.param212));
		} 
	}
	@Override  
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		if (requestCode == AppUtil.activity_photo_requestcode && resultCode != 0) {
			saveImage();
		}
	}
	/**
	 * 拍照后保存附件信息
	 */
	public void saveImage(){
		try {
			uuid = uuid1;
			savePath = savePath1;
			Bimp.setCompressor(ToolUtil.getFileFullPath(savePath),img_tp);
			//img_tp.setImageBitmap(Bimp.revitionImageSize(ToolUtil.getFileFullPath(savePath)));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	/**
	 * 保存图片路径
	 * @return
	 */
	private Uri getUri(){
		uuid1 = UUIDUtil.getUUID();
		String name = uuid1 + "." + wjlx;
		savePath1 = ToolUtil.getFilePath(name);
		String path = ToolUtil.getFileFullPath(savePath1);
		File file = new File(path);
		Uri imageUri  = null;
		if (Build.VERSION.SDK_INT >= 24) {
			imageUri =  FileProvider.getUriForFile(this, "com.jph.takephoto.fileprovider", file);//通过FileProvider创建一个content类型的Uri
		} else {
			imageUri = Uri.fromFile(file);
		}
		
		return imageUri;
	}
	public void updateGridView(){
		adapter.notifyDataSetChanged();
	}
	
	private void reset() {
		savePath = "";
		uuid = "";
		savePath1 = "";
		uuid1 = "";
		txt_gmjjdj_fjmc.setValue("");
		img_tp.setImageDrawable(this.getResources().getDrawable(R.drawable.icon_addpic_unfocused));
	}
	@Override
	public void showProgressDialog(String msg) {
		// TODO Auto-generated method stub
		mProgressDialog.setMessage(msg);
		mProgressDialog.show();
	}
	@Override
	public void hideProgressDialog() {
		// TODO Auto-generated method stub
		mProgressDialog.hide();
	}
	@Override
	public void showMessage(String msg) {
		// TODO Auto-generated method stub
		BaseToast.getInstance().ShowSystemToast(this, msg);
	}
	@Override
	public void getBmList(List<Item> arg0) {
		// TODO Auto-generated method stub
		bmjson=arg0;
		drawDownList_gmjjdj_jsr.setItem(bmjson);
		drawDownList_gmjjdj_jjr.setItem(bmjson);
	}
	
	class OnDetailClickListener implements OnJtcyXxDetailClickListener {
		@Override
		public void clickListener(int position) {
			detail(position);
		}

		private void detail(int position) {
			// TODO Auto-generated method stub
			scposition=position;
			config = new DialogConfig(GmJjDjActivity.this, getResources().getString(R.string.param221), true, exitClickListener);
			config.show();
		}
	}
	
	
	
	private OnClickListener exitClickListener = new  OnClickListener() {

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			DjjjdjItem scDjjjdjItem=items.get(scposition);
			TAppGmjjdjNy scTAppGmjjdjNy = new TAppGmjjdjNy();
			scTAppGmjjdjNy.setIfsc(2);
			scTAppGmjjdjNy.setId(items.get(scposition).getId());
			scmTAppGmjjDjNyList.add(scTAppGmjjdjNy);
			items.remove(scposition);
			adapter.notifyDataSetChanged();
			setListViewHeightBasedOnChildren(gmjjdj_list);
			config.dismiss();
		}
		
	};
	public void jjreset(){
		drawDownList_gmjjdj_zl.setValue("");
		gmjjdj_gmjjdj_zms.setText("");
		gmjjdj_gmjjdj_bz.setText("");
		gmjjdj_gmjjdj_sws_txt.setText("");
	}
	private void saveqbList() {
		// TODO Auto-generated method stub
		if(drawDownList_gmjjdj_gw.mEditText.getText().toString().equals("")){
			showMessage(getResources().getString(R.string.param222));
			return;
		}
		if(dataEditText.getText().toString().equals("")){
			showMessage(getResources().getString(R.string.param223));
			return;
		}
		if(drawDownList_gmjjdj_jsr.mEditText.getText().toString().equals("")){
			showMessage(getResources().getString(R.string.param224));
			return;
		}
		if(drawDownList_gmjjdj_jjr.mEditText.getText().toString().equals("")){
			showMessage(getResources().getString(R.string.param225));
			return;
		}
		if(gmjjdj_yjyzEditText.getText().toString().equals("")){
			showMessage(getResources().getString(R.string.param226));
			return;
		}
		if(gmjjdj_ysEditText.getText().toString().equals("")){
			showMessage(getResources().getString(R.string.param227));
			return;
		}
		if(radioGroupId==0){
			showMessage(getResources().getString(R.string.param228));
			return;
		}
		if(radioGroupId2==0){
			showMessage(getResources().getString(R.string.param229));
			return;
		}
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm"); 
		Date date=null;
		try {
			date = simpleDateFormat.parse(dataEditText.getText().toString());
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
		if(id!=null){
			mTAppGmjjDjJc.setId(Integer.valueOf(id));
			TAppYh user = BankApplication.mInstance.getCurrentUser();
			mTAppGmjjDjJc.setXgrMc(user.getSfz());
			mTAppGmjjDjJc.setXgrMc(user.getXm());
			mTAppGmjjDjJc.setXgsj(new Date());
			if(!gmjjdj_qtyjsxEditText.getText().toString().equals("")){
				mTAppGmjjDjJc.setQtBz(gmjjdj_qtyjsxEditText.getText().toString());
			}
			if(mTAppGmjjDjJc.getJsrMc().toString().equals(user.getXm())){
				 mTAppGmjjDjJc.setLczt(3);
				}
			if(mTAppGmjjDjJc.getJjrMc().toString().equals(user.getXm())){
					mTAppGmjjDjJc.setLczt(0);
				}
			if(mTAppGmjjDjJc.getJcrMc().toString().equals(user.getXm())){
				mTAppGmjjDjJc.setLczt(2);
				mTAppGmjjDjJc.setJcrMc(txt_jcr.getValue().toString());
				mTAppGmjjDjJc.setJcrSfz(user.getSfz());
				mTAppGmjjDjJc.setJsrMc(drawDownList_gmjjdj_jsr.getValue().toString());
				if(!drawDownList_gmjjdj_jsr.mEditText.getText().equals(mTAppGmjjDjJc.getJsrMc().toString())){
					mTAppGmjjDjJc.setJsrSfz(drawDownList_gmjjdj_jsr.getkey().toString());
					mTAppGmjjDjJc.setJsrMc(drawDownList_gmjjdj_jsr.getValue().toString());
				}
				if(!drawDownList_gmjjdj_jjr.mEditText.getText().toString().equals(mTAppGmjjDjJc.getJjrMc().toString())){
					mTAppGmjjDjJc.setJjrSfz(drawDownList_gmjjdj_jjr.getkey().toString());
					mTAppGmjjDjJc.setJjrMc(drawDownList_gmjjdj_jjr.getValue().toString());
				}
				mTAppGmjjDjJc.setJjrMc(drawDownList_gmjjdj_jjr.getValue().toString());
				mTAppGmjjDjJc.setYjyz(gmjjdj_yjyzEditText.getText().toString());
				mTAppGmjjDjJc.setYs(Integer.valueOf(gmjjdj_ysEditText.getText().toString()));
				mTAppGmjjDjJc.setYjyz(gmjjdj_yjyzEditText.getText().toString());
				mTAppGmjjDjJc.setSfXgMm(radioGroupId2);
				mTAppGmjjDjJc.setMmSfYj(radioGroupId);
				mTAppGmjjDjJc.setGw(Integer.parseInt(drawDownList_gmjjdj_gw.getkey().toString()));
			}
			if(fjxxList.size()>0){
				fjgxList= new ArrayList<TAppFjxxb>();
				for(TAppFjxxb mTAppFjxxb:fjxxList){
					if(mTAppFjxxb.getSczt()==0){
						fjgxList.add(mTAppFjxxb);
					}
				}
			}
			mTAppGmjjDjJc.setFjxxs(fjgxList);
			if(mTAppGmjjDjJc.getJjrMc().toString().equals(user.getXm()) && zhblr.equals(mTAppGmjjDjJc.getJsrMc().toString())){
				if(fjgxList==null || fjgxList.size()==0){
					showMessage(getResources().getString(R.string.param230));
					return;
				}
				
			}
			if(scfjList.size()>0){
				mTAppGmjjDjJc.setScfjList(scfjList);
			}
			List<TAppGmjjdjLc> tAppGmjjDjLcList = new ArrayList<TAppGmjjdjLc>();
			TAppGmjjdjLc mTAppGmjjDjLcgx = new TAppGmjjdjLc();
				if (mTAppGmjjDjJc.getJsrMc().toString().equals(user.getXm())) {
					mTAppGmjjDjLcgx.setRwId(2);
					mTAppGmjjDjLcgx.setSpZt(1);
					}
				if (mTAppGmjjDjJc.getJjrMc().toString().equals(user.getXm())) {
					mTAppGmjjDjLcgx.setRwId(3);
					mTAppGmjjDjLcgx.setSpZt(1);
				}
				if (mTAppGmjjDjJc.getJcrMc().toString().equals(user.getXm())) {
					mTAppGmjjDjLcgx.setRwId(1);
					mTAppGmjjDjLcgx.setSpZt(0);
					}
					mTAppGmjjDjLcgx.setCzrMc(user.getXm());
					mTAppGmjjDjLcgx.setCzrSfz(user.getSfz());
					mTAppGmjjDjLcgx.setCjsj(new Date());
					tAppGmjjDjLcList.add(mTAppGmjjDjLcgx);
	        mTAppGmjjDjJc.setmTAppGmjjdjLcList(tAppGmjjDjLcList);
	        if(items.size()>0){
	        	if(mTAppGmjjDjNyBeanList!=null && mTAppGmjjDjNyBeanList.size()>0){
	        	mTAppGmjjDjNyBeanList.clear();
	        	}else{
	        		mTAppGmjjDjNyBeanList= new ArrayList<TAppGmjjdjNy>();
	        	}
				for(int i=0;i<items.size();i++){
					TAppGmjjdjNy  mTAppGmjjDjNyBean= new TAppGmjjdjNy();
					mTAppGmjjDjNyBean.setJjzl(Integer.valueOf(items.get(i).getKey()));
					mTAppGmjjDjNyBean.setZms(new BigDecimal(items.get(i).getValue()));
					String bz=items.get(i).getBz();
					if(bz==null || bz.equals("")){
					mTAppGmjjDjNyBean.setBz("");}
					else{
						mTAppGmjjDjNyBean.setBz(items.get(i).getBz());
					}
					mTAppGmjjDjNyBean.setSws(items.get(i).getSws());
					mTAppGmjjDjNyBean.setId(items.get(i).getId());
					mTAppGmjjDjNyBean.setIfsc(0);
					mTAppGmjjDjNyBeanList.add(mTAppGmjjDjNyBean);
				}
				mTAppGmjjDjJc.setmTAppGmjjdjNyList(mTAppGmjjDjNyBeanList);
			}
	        if(scmTAppGmjjDjNyList.size()>0){
	        	mTAppGmjjDjJc.setScTAppGmjjdjNyList(scmTAppGmjjDjNyList);
	        }
	        
			List<TAppGmjjdjJc> mTAppGmjjDjJcList = new ArrayList<TAppGmjjdjJc>();
			mTAppGmjjDjJcList.add(mTAppGmjjDjJc);
			String str = GsonUtil.getGson().toJson(mTAppGmjjDjJcList);
			presenter.savegxqbList(str);
			
		}
		else{
		mTAppGmjjDjJc.setId(Integer.valueOf(djId));
		mTAppGmjjDjJc.setGw(Integer.parseInt(drawDownList_gmjjdj_gw.getkey().toString()));
//		mTAppGmjjDjJc.setJjsj(date);
		mTAppGmjjDjJc.setJssj(date);
		mTAppGmjjDjJc.setCjsj(new Date());
		mTAppGmjjDjJc.setJcrMc(txt_jcr.getValue().toString());
		TAppYh user = BankApplication.mInstance.getCurrentUser();
		mTAppGmjjDjJc.setJcrSfz(user.getSfz());
		mTAppGmjjDjJc.setJsrMc(drawDownList_gmjjdj_jsr.getValue().toString());
		mTAppGmjjDjJc.setJsrSfz(drawDownList_gmjjdj_jsr.getkey().toString());
		mTAppGmjjDjJc.setJjrMc(drawDownList_gmjjdj_jjr.getValue().toString());
		mTAppGmjjDjJc.setJjrSfz(drawDownList_gmjjdj_jjr.getkey().toString());
		mTAppGmjjDjJc.setYjyz(gmjjdj_yjyzEditText.getText().toString());
		mTAppGmjjDjJc.setYs(Integer.valueOf(gmjjdj_ysEditText.getText().toString()));
		mTAppGmjjDjJc.setXgrSfz(user.getSfz());
		mTAppGmjjDjJc.setXgsj(new Date());
		mTAppGmjjDjJc.setXgrMc(user.getXm());
		mTAppGmjjDjJc.setLczt(2);
		mTAppGmjjDjJc.setMmSfYj(radioGroupId);
		mTAppGmjjDjJc.setSfXgMm(radioGroupId2);
		if(!gmjjdj_qtyjsxEditText.getText().toString().equals("")){
			mTAppGmjjDjJc.setQtBz(gmjjdj_qtyjsxEditText.getText().toString());
		}
		if(items.size()>0){
			for(int i=0;i<items.size();i++){
				TAppGmjjdjNy  mTAppGmjjDjNyBean= new TAppGmjjdjNy();
				mTAppGmjjDjNyBean.setJjzl(Integer.valueOf(items.get(i).getKey()));
				mTAppGmjjDjNyBean.setZms(new BigDecimal(items.get(i).getValue()));
				mTAppGmjjDjNyBean.setSws(items.get(i).getSws());
				mTAppGmjjDjNyBean.setBz(items.get(i).getBz());
				mTAppGmjjDjNyBeanList.add(mTAppGmjjDjNyBean);
			}
			mTAppGmjjDjJc.setmTAppGmjjdjNyList(mTAppGmjjDjNyBeanList);
		}
        List<TAppGmjjdjLc> tAppGmjjDjLcList = new ArrayList<TAppGmjjdjLc>();
        TAppGmjjdjLc mTAppGmjjDjLc= new TAppGmjjdjLc();
        		mTAppGmjjDjLc.setRwId(1);
        		mTAppGmjjDjLc.setCzrMc(user.getXm());
        		mTAppGmjjDjLc.setCzrSfz(user.getSfz());
        		mTAppGmjjDjLc.setCjsj(new Date());
        tAppGmjjDjLcList.add(mTAppGmjjDjLc);
        mTAppGmjjDjJc.setmTAppGmjjdjLcList(tAppGmjjDjLcList);
        if(fjxxList.size()>0){
        	mTAppGmjjDjJc.setFjxxs(fjxxList);
		}
		List<TAppGmjjdjJc> mTAppGmjjDjJcList = new ArrayList<TAppGmjjdjJc>();
		mTAppGmjjDjJcList.add(mTAppGmjjDjJc);
		String str = GsonUtil.getGson().toJson(mTAppGmjjDjJcList);
		presenter.saveqbList(str);
		}
		
	}
	@Override
	public void scsuccess() {
		// TODO Auto-generated method stub
		Intent intent= new Intent();
		intent.setClass(GmJjDjActivity.this, DbJjDjActivity.class);
		startActivity(intent);
		finish();
	}
	@Override
	public void getDbList(List<DbjjItem> arg0) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void getdbjjdjList(List<TAppGmjjdjJc> arg0) {
		// TODO Auto-generated method stub
		mTAppGmjjDjJc=arg0.get(0);
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm"); 
//		Date date=mTAppGmjjDjJc.getJjsj();
		Date date=mTAppGmjjDjJc.getJssj();
		String str=simpleDateFormat.format(date); 
		drawDownList_gmjjdj_gw.setValue(mTAppGmjjDjJc.getGw()+"");
		drawDownList_gmjjdj_gw.mEditText.setEnabled(false);
		dataEditText.setText(str);
		txt_jcr.mEditText.setText(mTAppGmjjDjJc.getJcrMc());
		txt_jcr.mEditText.setEnabled(false);
		drawDownList_gmjjdj_jsr.mEditText.setText(mTAppGmjjDjJc.getJsrMc());
		drawDownList_gmjjdj_jjr.mEditText.setText(mTAppGmjjDjJc.getJjrMc());
//		drawDownList_gmjjdj_jsr.setValue(mTAppGmjjDjJc.getJsrSfz().toString());
//		drawDownList_gmjjdj_jjr.setValue(mTAppGmjjDjJc.getJjrSfz().toString());
		gmjjdj_yjyzEditText.setText(mTAppGmjjDjJc.getYjyz());
		gmjjdj_ysEditText.setText(mTAppGmjjDjJc.getYs()+"");
		radioGroupId=mTAppGmjjDjJc.getMmSfYj();
		radioGroupId2 = mTAppGmjjDjJc.getSfXgMm();
		if(radioGroupId==1){
			radioButton_shiRadioButton.setChecked(true);
			radioButton_fouRadioButton.setEnabled(false);
			radioButton_weiRadioButton.setEnabled(false);
		}else if(radioGroupId==2){
			radioButton_shiRadioButton.setEnabled(false);
			radioButton_fouRadioButton.setChecked(true);
			radioButton_weiRadioButton.setEnabled(false);
		}else if(radioGroupId==3){
			radioButton_shiRadioButton.setEnabled(false);
			radioButton_fouRadioButton.setEnabled(false);
			radioButton_weiRadioButton.setChecked(true);
		}
		if(radioGroupId2==1){
			radioButton_shiRadioButton2.setChecked(true);
			radioButton_fouRadioButton2.setEnabled(false);
			radioButton_weiRadioButton2.setEnabled(false);
		}else if(radioGroupId2==2){
			radioButton_shiRadioButton2.setEnabled(false);
			radioButton_fouRadioButton2.setChecked(true);
			radioButton_weiRadioButton2.setEnabled(false);
		}else if(radioGroupId2==3){
			radioButton_shiRadioButton2.setEnabled(false);
			radioButton_fouRadioButton2.setEnabled(false);
			radioButton_weiRadioButton2.setChecked(true);
		}
		gmjjdj_qtyjsxEditText.setText(mTAppGmjjDjJc.getQtBz());
		mTAppGmjjDjNyBeanList = mTAppGmjjDjJc.getmTAppGmjjdjNyList();
		if(mTAppGmjjDjNyBeanList!=null && mTAppGmjjDjNyBeanList.size()>0){
			for(TAppGmjjdjNy mTAppGmjjdjNy:mTAppGmjjDjNyBeanList){
				DjjjdjItem  mImageItem=new DjjjdjItem();
				mImageItem.setKey(mTAppGmjjdjNy.getJjzl()+"");
				mImageItem.setId(mTAppGmjjdjNy.getId());
				drawDownList_gmjjdj_zl.setValue(mTAppGmjjdjNy.getJjzl()+"");
				mImageItem.setImg(drawDownList_gmjjdj_zl.mEditText.getText().toString());
				drawDownList_gmjjdj_zl.mEditText.setText("");
				mImageItem.setValue(mTAppGmjjdjNy.getZms()+"");
				mImageItem.setBz(mTAppGmjjdjNy.getBz());
				mImageItem.setSws(new BigDecimal(mTAppGmjjdjNy.getSws().toString()));
				mImageItem.setGnlj("删除");
				items.add(mImageItem);
				
				
			}
			adapter.notifyDataSetChanged();
			setListViewHeightBasedOnChildren(gmjjdj_list);
			
			
			
		}
		List<TAppFjxxb> fjxx = mTAppGmjjDjJc.getFjxxs();
		String bs=mTAppGmjjDjJc.getJcrMc();
		TAppYh user = BankApplication.mInstance.getCurrentUser();
		if(fjxx!=null && fjxx.size()>0){
			for (TAppFjxxb mTAppFjxxb : fjxx) {
				String wjlx=mTAppFjxxb.getWjmc();
				String wjlxx = wjlx.substring(wjlx.lastIndexOf(".") + 1, wjlx.length());
				mTAppFjxxb.setWjlx(wjlxx);
				mTAppFjxxb.setAppdz(ToolUtil.getFilePath(mTAppFjxxb.getUuid() +"."+wjlxx));
				mTAppFjxxb.setGnmk(4);
				if(user.getXm().equals(bs) && lczt.equals("2")){
					mTAppFjxxb.setSczt(3);
				}else if(user.getXm().equals(bs) && lczt.equals("1")){
					mTAppFjxxb.setSczt(3);
				}
				else{
				mTAppFjxxb.setSczt(1);}
				mTAppFjxxb.setUuid(mTAppFjxxb.getUuid());
				fjxxList.add(mTAppFjxxb);
			}
			updateGridView();
			setListViewHeightBasedOnChildren(gmjjdj_fj_gridview);
		}
		
		quangxian();
		
		
	}
	

	private void quangxian(){
		
		String json = BankApplication.mInstance.getCurrentUserForJson();
		TAppYh user = GsonUtil.getGson().fromJson(json, TAppYh.class);
		if(!zhblr.equals("")){
			if(mTAppGmjjDjJc.getJsrMc().toString().equals(user.getXm()) && zhblr.equals(mTAppGmjjDjJc.getJcrMc().toString())){
				gmjjdj_yjhsfxgmm_layout.setVisibility(View.VISIBLE);
				gmjjdj_yjhsfxgmm.setVisibility(View.VISIBLE);
				gmjjdj_sws_label.setVisibility(View.VISIBLE);
				gmjjdj_gmjjdj_sws_txt.setVisibility(View.VISIBLE);
				gmjjdj_gmjjdj_sws_txt.setEnabled(false);
				gmjjdj_tjjjnr_bc.setVisibility(View.GONE);
				gmjjdj_tj_button.setText("同意");
				gmjjdj_bty_button.setVisibility(View.VISIBLE);
				gmjjdj_tj_fjButton.setVisibility(View.GONE);
				gmjjdj_gmjjdj_zms.setEnabled(false);
				img_tp.setVisibility(View.GONE);
				adapter.setmOnJtcyXxDetailClickListener(null);
				txt_gmjjdj_fjmc.mEditText.setVisibility(View.GONE);
				drawDownList_gmjjdj_zl.mEditText.setEnabled(false);
				gbbj();
			}
			if(mTAppGmjjDjJc.getJsrMc().toString().equals(user.getXm()) && zhblr.equals(mTAppGmjjDjJc.getJsrMc().toString())){
				gbbj();
				gmjjdj_yjhsfxgmm_layout.setVisibility(View.VISIBLE);
				gmjjdj_yjhsfxgmm.setVisibility(View.VISIBLE);
				gmjjdj_sws_label.setVisibility(View.VISIBLE);
				gmjjdj_gmjjdj_sws_txt.setVisibility(View.VISIBLE);
				gmjjdj_tj_fjButton.setVisibility(View.GONE);
				gmjjdj_tj_button.setVisibility(View.GONE);
				gmjjdj_bty_button.setVisibility(View.GONE);
				gmjjdj_gmjjdj_zms.setEnabled(false);
				adapter.setmOnJtcyXxDetailClickListener(null);
				img_tp.setVisibility(View.GONE);
				txt_gmjjdj_fjmc.mEditText.setVisibility(View.GONE);
				drawDownList_gmjjdj_zl.mEditText.setEnabled(false);
//				fjadapter.setmOnDeleteListener(null);
				
			}
			if(mTAppGmjjDjJc.getJjrMc().toString().equals(user.getXm()) && zhblr.equals(mTAppGmjjDjJc.getJsrMc().toString()) && spzt.equals("1")){
				gmjjdj_yjhsfxgmm_layout.setVisibility(View.VISIBLE);
				gmjjdj_yjhsfxgmm.setVisibility(View.VISIBLE);
				gmjjdj_sws_label.setVisibility(View.VISIBLE);
				gmjjdj_gmjjdj_sws_txt.setVisibility(View.VISIBLE);
				gmjjdj_tj_button.setText("同意");
				gmjjdj_tj_button.setVisibility(View.VISIBLE);
				gmjjdj_bty_button.setVisibility(View.VISIBLE);
				gmjjdj_gmjjdj_zms.setEnabled(false);
				gmjjdj_gmjjdj_sws_txt.setEnabled(false);
				adapter.setmOnJtcyXxDetailClickListener(null);
				drawDownList_gmjjdj_zl.mEditText.setEnabled(false);
//				fjadapter.setmOnDeleteListener(null);
				gbbj();
			}
			
			if(mTAppGmjjDjJc.getJjrMc().toString().equals(user.getXm()) && zhblr.equals(mTAppGmjjDjJc.getJjrMc().toString())){
				gbbj();
				gmjjdj_yjhsfxgmm_layout.setVisibility(View.VISIBLE);
				gmjjdj_yjhsfxgmm.setVisibility(View.VISIBLE);
				gmjjdj_sws_label.setVisibility(View.VISIBLE);
				gmjjdj_gmjjdj_sws_txt.setVisibility(View.VISIBLE);
				gmjjdj_tj_fjButton.setVisibility(View.GONE);
				gmjjdj_tj_button.setVisibility(View.GONE);
				gmjjdj_gmjjdj_zms.setEnabled(false);
				drawDownList_gmjjdj_zl.mEditText.setEnabled(false);
//				adapter.setmOnJtcyXxDetailClickListener(null);
//				fjadapter.setmOnDeleteListener(null);
			}
			if(mTAppGmjjDjJc.getJjrMc().toString().equals(user.getXm()) && zhblr.equals(mTAppGmjjDjJc.getJcrMc())){
				gbbj();
				gmjjdj_tj_fjButton.setVisibility(View.GONE);
				gmjjdj_tj_button.setVisibility(View.GONE);
				gmjjdj_bty_button.setVisibility(View.GONE);
				gmjjdj_tjjjnr_bc.setVisibility(View.GONE);
				gmjjdj_gmjjdj_zms.setEnabled(false);
				adapter.setmOnJtcyXxDetailClickListener(null);
				img_tp.setVisibility(View.GONE);
				txt_gmjjdj_fjmc.mEditText.setVisibility(View.GONE);
			}
			if(mTAppGmjjDjJc.getJjrMc().toString().equals(user.getXm()) && zhblr.equals(mTAppGmjjDjJc.getJsrMc()) && spzt.equals("2")){
				gbbj();
				gmjjdj_tj_fjButton.setVisibility(View.GONE);
				gmjjdj_tj_button.setVisibility(View.GONE);
				gmjjdj_bty_button.setVisibility(View.GONE);
				gmjjdj_tjjjnr_bc.setVisibility(View.GONE);
				gmjjdj_gmjjdj_zms.setEnabled(false);
				adapter.setmOnJtcyXxDetailClickListener(null);
				img_tp.setVisibility(View.GONE);
				txt_gmjjdj_fjmc.mEditText.setVisibility(View.GONE);
			}
			
			if(mTAppGmjjDjJc.getJcrMc().toString().equals(user.getXm()) && zhblr.equals(mTAppGmjjDjJc.getJsrMc().toString()) && spzt.equals("2")){
				gmjjdj_tj_fjButton.setVisibility(View.VISIBLE);
				gmjjdj_tj_button.setVisibility(View.VISIBLE);
				gmjjdj_bty_button.setVisibility(View.GONE);
				gmjjdj_tjjjnr_bc.setVisibility(View.VISIBLE);
				gmjjdj_tjjjnrButton.setVisibility(View.VISIBLE);
				radioButton_shiRadioButton.setEnabled(true);
				radioButton_fouRadioButton.setEnabled(true);
				radioButton_weiRadioButton.setEnabled(true);
			}
			
			if(mTAppGmjjDjJc.getJcrMc().toString().equals(user.getXm()) && zhblr.equals(mTAppGmjjDjJc.getJjrMc().toString()) && spzt.equals("2")){
				gmjjdj_tj_fjButton.setVisibility(View.VISIBLE);
				gmjjdj_tj_button.setVisibility(View.VISIBLE);
				gmjjdj_bty_button.setVisibility(View.GONE);
				gmjjdj_tjjjnr_bc.setVisibility(View.VISIBLE);
				gmjjdj_tjjjnrButton.setVisibility(View.VISIBLE);
				gmjjdj_tj_fjButton.setVisibility(View.VISIBLE);
				radioButton_shiRadioButton.setEnabled(true);
				radioButton_fouRadioButton.setEnabled(true);
				radioButton_weiRadioButton.setEnabled(true);
			}
			if(mTAppGmjjDjJc.getJsrMc().toString().equals(user.getXm()) && zhblr.equals(mTAppGmjjDjJc.getJjrMc().toString()) && spzt.equals("2")){
				gmjjdj_tj_fjButton.setVisibility(View.VISIBLE);
				gmjjdj_tj_button.setVisibility(View.GONE);
//				gmjjdj_bty_button.setVisibility(View.VISIBLE);
				gmjjdj_tjjjnr_bc.setVisibility(View.VISIBLE);
				gmjjdj_tjjjnrButton.setVisibility(View.VISIBLE);
				gmjjdj_yjhsfxgmm_layout.setVisibility(View.VISIBLE);
				gmjjdj_yjhsfxgmm.setVisibility(View.VISIBLE);
				gmjjdj_sws_label.setVisibility(View.VISIBLE);
				gmjjdj_gmjjdj_sws_txt.setVisibility(View.VISIBLE);
				gbbj();
				
			}
			if(mTAppGmjjDjJc.getJcrMc().toString().equals(user.getXm()) && lczt.equals("3")){
				gbbj();
				gmjjdj_tj_button.setVisibility(View.GONE);
				gmjjdj_bty_button.setVisibility(View.GONE);
				adapter.setmOnJtcyXxDetailClickListener(null);
				fjadapter.setmOnDeleteListener(null);
				img_tp.setVisibility(View.GONE);
				txt_gmjjdj_fjmc.mEditText.setVisibility(View.GONE);
				gmjjdj_tj_fjButton.setVisibility(View.GONE);
			}
			if(mTAppGmjjDjJc.getJcrMc().toString().equals(user.getXm()) && lczt.equals("1")){
				gmjjdj_tjjjnr_bc.setVisibility(View.VISIBLE);
				radioButton_shiRadioButton.setEnabled(true);
				radioButton_fouRadioButton.setEnabled(true);
				radioButton_weiRadioButton.setEnabled(true);
				radioButton_shiRadioButton2.setEnabled(true);
				radioButton_fouRadioButton2.setEnabled(true);
				radioButton_weiRadioButton2.setEnabled(true);
				gmjjdj_qtyjsxEditText.setEnabled(true);
				gmjjdj_gmjjdj_bz.setEnabled(true);
				
			}
			if(mTAppGmjjDjJc.getJcrMc().toString().equals(user.getXm()) && lczt.equals("2")){
				gmjjdj_tjjjnr_bc.setVisibility(View.VISIBLE);
				radioButton_shiRadioButton.setEnabled(true);
				radioButton_fouRadioButton.setEnabled(true);
				radioButton_weiRadioButton.setEnabled(true);
				radioButton_shiRadioButton2.setEnabled(true);
				radioButton_fouRadioButton2.setEnabled(true);
				radioButton_weiRadioButton2.setEnabled(true);
				gmjjdj_qtyjsxEditText.setEnabled(true);
				gmjjdj_gmjjdj_bz.setEnabled(true);
			}
			
			
			
		}
	}
	public void gbbj(){
		gmjjdj_tjjjnrButton.setVisibility(View.GONE);
		drawDownList_gmjjdj_gw.mEditText.setEnabled(false);
		dataEditText.setEnabled(false);
		drawDownList_gmjjdj_jsr.mEditText.setEnabled(false);
		drawDownList_gmjjdj_jjr.mEditText.setEnabled(false);
		txt_jcr.mEditText.setEnabled(false);
		gmjjdj_yjyzEditText.setEnabled(false);
		gmjjdj_ysEditText.setEnabled(false);
		dataImageView.setEnabled(false);
		gmjjdj_qtyjsxEditText.setEnabled(false);
		gmjjdj_gmjjdj_bz.setEnabled(false);
	}
//	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3){
//		Intent intent = new Intent(GmJjDjActivity.this, GmjjPhotoActivity.class);
//		intent.putExtra("fjxxList", (Serializable)fjxxList);
//		intent.putExtra("ID", arg2);
//		this.startActivity(intent);
//	}
	public void btyDialog(){
		final EditText input = new EditText(this);
		final AlertDialog.Builder  btydialog= new AlertDialog.Builder(this);
		btydialog.setTitle("请填写原因");
		btydialog.setView(input);
		input.setBackgroundColor(Color.WHITE);
		btydialog.setPositiveButton("提交并退至交出人", new DialogInterface.OnClickListener() {
			
			@Override
			public void onClick(DialogInterface dialog, int which) {
				// TODO Auto-generated method stub
				yjtxt=input.getText().toString();
				savebtyyy(1,yjtxt);
				
				
			}
		});
		btydialog.setNeutralButton("取消", new DialogInterface.OnClickListener() {
			
			@Override
			public void onClick(DialogInterface dialog, int which) {
				// TODO Auto-generated method stub
				
			}
		});
		
		btydialog.show();
	}
	public void savebtyyy(int rwid,String yy){
		mTAppGmjjDjJc.setId(Integer.valueOf(id));
		mTAppGmjjDjJc.setSfXgMm(radioGroupId2);
		TAppYh user = BankApplication.mInstance.getCurrentUser();
		mTAppGmjjDjJc.setXgrMc(user.getSfz());
		mTAppGmjjDjJc.setXgrMc(user.getXm());
		mTAppGmjjDjJc.setXgsj(new Date());
		if(mTAppGmjjDjJc.getJsrMc().toString().equals(user.getXm())){
			mTAppGmjjDjJc.setLczt(rwid);
		}
       if(mTAppGmjjDjJc.getJjrMc().toString().equals(user.getXm())){
			mTAppGmjjDjJc.setLczt(rwid);
		}
		
		if(fjxxList.size()>0){
			fjgxList= new ArrayList<TAppFjxxb>();
			for(TAppFjxxb mTAppFjxxb:fjxxList){
				if(mTAppFjxxb.getSczt()!=1){
					fjgxList.add(mTAppFjxxb);
				}
			}
			mTAppGmjjDjJc.setFjxxs(fjgxList);
		}
		if(mTAppGmjjDjJc.getJjrMc().toString().equals(user.getXm()) && zhblr.equals(mTAppGmjjDjJc.getJsrMc().toString())){
//			if(fjgxList==null || fjgxList.size()==0){
//				showMessage("监交人要拍照");
//				return;
//			}
			
		}
		List<TAppGmjjdjLc> tAppGmjjDjLcList = new ArrayList<TAppGmjjdjLc>();
        TAppGmjjdjLc mTAppGmjjDjLcgx= new TAppGmjjdjLc();
        if(mTAppGmjjDjJc.getJsrMc().toString().equals(user.getXm())){
        	mTAppGmjjDjLcgx.setRwId(2);
		}
        if(mTAppGmjjDjJc.getJjrMc().toString().equals(user.getXm())){
			mTAppGmjjDjLcgx.setRwId(3);
		}
        
        mTAppGmjjDjLcgx.setCzrMc(user.getXm());
        mTAppGmjjDjLcgx.setCzrSfz(user.getSfz());
        mTAppGmjjDjLcgx.setCjsj(new Date());
        mTAppGmjjDjLcgx.setSpZt(2);
        mTAppGmjjDjLcgx.setSpyj(yy);
        tAppGmjjDjLcList.add(mTAppGmjjDjLcgx);
        mTAppGmjjDjJc.setmTAppGmjjdjLcList(tAppGmjjDjLcList);
        if(items.size()>0){
        	mTAppGmjjDjNyBeanList.clear();
			for(int i=0;i<items.size();i++){
				TAppGmjjdjNy  mTAppGmjjDjNyBean= new TAppGmjjdjNy();
				mTAppGmjjDjNyBean.setJjzl(Integer.valueOf(items.get(i).getKey()));
				mTAppGmjjDjNyBean.setZms(new BigDecimal(items.get(i).getValue()));
				mTAppGmjjDjNyBean.setBz(items.get(i).getBz());
				mTAppGmjjDjNyBean.setSws(items.get(i).getSws());;
				mTAppGmjjDjNyBean.setId(items.get(i).getId());
				mTAppGmjjDjNyBeanList.add(mTAppGmjjDjNyBean);
			}
			mTAppGmjjDjJc.setmTAppGmjjdjNyList(mTAppGmjjDjNyBeanList);
		}
        
		List<TAppGmjjdjJc> mTAppGmjjDjJcList = new ArrayList<TAppGmjjdjJc>();
		mTAppGmjjDjJcList.add(mTAppGmjjDjJc);
		String str = GsonUtil.getGson().toJson(mTAppGmjjDjJcList);
		presenter.savegxqbList(str);
	}
	
	class DeleteOnClickListener implements OnDeleteListener{

		@Override
		public void clickListener(int position) {
			// TODO Auto-generated method stub
			TAppFjxxb  mTAppFjxxb=fjxxList.get(position);
			scfjList.add(mTAppFjxxb);
			fjxxList.remove(position);
			updateGridView();
			setListViewHeightBasedOnChildren(gmjjdj_fj_gridview);
		}
		
	}
	public void ifSaveList(){
		new AlertDialog.Builder(this).setTitle("是否确认提交").setIcon(android.R.drawable.ic_dialog_info)
		.setPositiveButton("确定", new DialogInterface.OnClickListener() {
			
			@Override
			public void onClick(DialogInterface dialog, int which) {
				// TODO Auto-generated method stub
				saveqbList();
			}
		}).setNegativeButton("取消", new DialogInterface.OnClickListener() {
			
			@Override
			public void onClick(DialogInterface dialog, int which) {
				// TODO Auto-generated method stub
				
			}
		}).show();
	}
	@Override
	public void getGwList(List<Item> arg0) {
		// TODO Auto-generated method stub
//		Item item=new Item();
//		item.setKey("0");
//		item.setValue("无岗位");
//		gwjson.add(item);
		gwjson=arg0;
//		if(arg0!=null && !arg0.isEmpty()){
//			for(int i=0;i<arg0.size();i++){
//				Item items=new Item();
//				items.setKey(arg0.get(i).getKey());
//				items.setValue(arg0.get(i).getValue());
//				gwjson.add(items);
//			}
////			gwjson.add(arg0);
//		}
		drawDownList_gmjjdj_gw.setItem(gwjson);
		String json = BankApplication.mInstance.getCurrentUserForJson();
		TAppYh user = GsonUtil.getGson().fromJson(json, TAppYh.class);
		if(id!=null){
			presenter.getDbjjdjJson(id);;
		}else{
			String xl="{\"sfz\":\""+user.getSfz()+"\",\"bs\":\""+xlbs+"\"}";
			presenter.getdjJson(xl);
		}
	}
	@Override
	public void getdjJson(List<TAppGmjjdjJc> arg0) {
		// TODO Auto-generated method stub
		if(arg0!=null && arg0.size()>0){
			mTAppGmjjDjJc=arg0.get(0);
			lczt=mTAppGmjjDjJc.getLczt()+"";
			djId=mTAppGmjjDjJc.getId()+"";
			SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm"); 
			Date date=mTAppGmjjDjJc.getJssj();
			String str=simpleDateFormat.format(date); 
			drawDownList_gmjjdj_gw.setValue(mTAppGmjjDjJc.getGw()+"");
			dataEditText.setText(str);
			txt_jcr.mEditText.setText(mTAppGmjjDjJc.getJcrMc());
		}
		if(gwjson.size()>1 && lczt.equals("9")){
		drawDownList_gmjjdj_gw.setOnSelectListener(new OnSelectListener() {
			
			@Override
			public void onchange(String key, String val) {
				// TODO Auto-generated method stub
				xlbs=key;
				String json = BankApplication.mInstance.getCurrentUserForJson();
				TAppYh user = GsonUtil.getGson().fromJson(json, TAppYh.class);
				String xl="{\"sfz\":\""+user.getSfz()+"\",\"bs\":\""+xlbs+"\"}";
				presenter.getdjJson(xl);
			}
		});
	}
		}
	@Override
	public void deleteJson(String arg0) {
		// TODO Auto-generated method stub
	}
	private TextWatcher watcher = new TextWatcher() {
        @Override
        public void afterTextChanged(Editable s) {
            // TODO Auto-generated method stub
            String temp = s.toString().trim();
            //如果数据以小数点开头，就清空。因为手机的处理速度，怎么也比手动输入的速度快，所以给人感觉是：开头输小数点，输不进去
            if (s.toString().startsWith(".")) {
            	gmjjdj_gmjjdj_zms.setText("");
            }

            int posDot = temp.indexOf(".");
            if (posDot <= 0)
                return;
            if (temp.length() - posDot - 1 > ACCURACYNUM) {
                s.delete(posDot + ACCURACYNUM + 1, posDot + ACCURACYNUM + 2);
            }
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count,
                                      int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before,
                                  int count) {
        }
    };

}